package com.bjpowernode.javaweb.servlet;

import com.bjpowernode.javaweb.bean.User;
import com.bjpowernode.javaweb.bean.User2;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/session/binding")
public class HttpSessionBindingListenerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession();

        User user=new User("zhangsan","111","123");
        User2 user2=new User2("zhangsan","111","123");

        //将user类存储到session域
        session.setAttribute("user1",user);
        session.setAttribute("user2",user2);
    }
}
